<template>
	<div class="container">
	    <div class="login-form">
	      <div class="text">注册</div>
	      <div class="form-item">
	        <input type="text"  v-model="form.account" placeholder="邮箱">
			<input type="text"  v-model="form.name" placeholder="昵称">
	        <input type="password" v-model="form.password" placeholder="密码">
			<input type="text" v-model="form.yzm" placeholder="验证码">
			<input type="button" value="点击获取验证码" @click="createYzm()"/>
	      </div>
	      <div class="btn" @click="save()">保存</div>
	      <div class="btn-back"></div>
	      <div class="other">
	        已有账号？<router-link to="/userlogin">去登录</router-link>
	      </div>
	    </div>
	  </div>
</template>

<script>
	import router from "@/router";

  export default{
		data(){
			return{
				 form:{
					 account:"1503608495@qq.com",
           name:"",
					 password:"",
					 yzm:""
				 },
			}
		},
		methods:{
      createYzm(){
      //      createYzm
        if(this.form.account.length==0){
          this.$message({message:"邮箱不能为空！",type:'warning'});
          return ;
        }
        this.$http.get("userApi/userCtl/createYzm?account="+this.form.account).then((resp)=> {
          if (resp.data.code == 200) {
            this.$message({message:resp.data.message,type:'success'});
          }else if (resp.data.code==203){
            this.$message({message:resp.data.message,type:'warning'});
          }
        })
      },
      save(){
        if(this.form.name.length==0){
          this.$message({message:"昵称不能为空！",type:'warning'});
          return ;
        }
        if(this.form.password.length==0){
          this.$message({message:"密码不能为空！",type:'warning'});
          return ;
        }
        if(this.form.yzm.length==0){
          this.$message({message:"验证码不能为空！",type:'warning'});
          return ;
        }
        this.$http.post("userApi/userCtl/save",this.form).then((resp)=>{
          console.log(resp)
          if (resp.data.code==200){
            if (resp.data.data==0){
              this.$message({message:"验证码失效！",type:'warning'});
            }
            if (resp.data.data==1){
              this.$message({message:"验证码错误！",type:'warning'});
            }
            if (resp.data.data==2){
              this.$message({message:"注册成功！",type:'success'});
              router.replace("/userlogin");
            }
          }
        })
      }
		}
		
	}
</script>

<style src="../../assets/css/userlogin.css" scoped></style>
